# coding:utf-8
"""
@author: 井松
@contact: 529548204@qq.com
@file: serializers.py.py
@time: 2021/10/19 14:29
"""
from rest_framework import serializers,exceptions
from article.models import Article

def about_django(value):
    if value!=2:
        raise exceptions.ValidationError("必填")

class ArticleListSerializer(serializers.ModelSerializer):
    title = serializers.CharField(label='标题', max_length=20, validators=[about_django])

    class Meta:
        model = Article
        fields = [
            'id',
            'title',
            'created'
        ]

    # def validate(self, art):


class ArticleDetailSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article

        fields = '__all__'
